﻿ //占位1px空白图片
    Ext.BLANK_IMAGE_URL='commons/img/s.gif';
    var resetpwdDlg;        //设置密码窗口
    /**
     * 创建头部html
     * @return {}
     */
    function northHtml(){
        //顶部HTML字符串
        var s='<div class="index-top-bg" style=" height:58px;display:block;">'+
                '<table width="100%" border="0" cellspacing="0" cellpadding="0">'+
                '  <tr>'+
                '    <td width="33%" height="25"><span style="font-size: 20px;font-weight: bold;padding-left:10px;">邢台市国税局加油站税控管理系统</span></td>'+
                '    <td width="16%"></td>'+
                '    <td width="51%"></td>'+
                '  </tr>'+
                '  <tr>'+
                '    <td height="25"><span id="svrtime" style="padding-left:25px;"></span></td>'+
                '    <td align="center"><span id="sTabLoading" style="color: #E11E1E;display: none;">正在加载...</span></td>'+
                '    <td align="right"><span id="swry_mc">操作员：</span>&nbsp;&nbsp;&nbsp;&nbsp;<span id="swjg_mc">税务机关：</span>&nbsp;&nbsp;&nbsp;&nbsp;'+
                '        <a href="javascript:resetpwd()">修改密码</a>&nbsp;&nbsp;&nbsp;&nbsp;'+
                 '       <a href="javascript:reLogin()">注销</a>&nbsp;&nbsp;&nbsp;&nbsp;'+
                '        <a href="javascript:exitSYS()">退出系统</a>&nbsp;&nbsp;&nbsp;&nbsp;'+
                '        <a href="javascript:about()">关于</a>&nbsp;&nbsp;&nbsp;&nbsp;</td>'+
                '  </tr>'+
                '</table></div>';
        return s;
    }
    /**
     * 创建底部html
     * @return {}
     */
    function southHtml(){
        var s='<div class="index-buttom-bg" style="display:block;height:25px; text-align:center;">'+
                '<span class="index-buttom-txt">Copyright &copy; 2013 版本:1.0 服务单位：邢台金税科技有限责任公司 服务热线：2219202 2219203</span>'+
                '</div>';
        return s;
    }
    ////获取左列菜单数据
    var menuStore=Ext.create('Ext.data.TreeStore', {
        proxy: {
            type: 'ajax',
            url: 'menuAction.action'
        }
/*
        root: {
            expanded: true
        },
        sorters: [{
        }]*/

    });
    ///////////////////////////////////////
    //创建4个面板
    var panelNorth=Ext.create('Ext.panel.Panel',{
                        region:'north',
                        height:58,
                        html:northHtml()
                    });
    var panelWest=Ext.create('Ext.tree.Panel',{
                        region:'west',
                        width:200,
                        title:'导航菜单',
                        split:true,
                        collapsible:true,
                        store: menuStore,
                        autoScroll:true,
                        rootVisible:false,
                        useArrows: true,
                        listeners:{
                            itemclick:{
                                fn: function(view,record,item,index,e){
                                    if (record.raw.leaf=='true'){
                                        addTab(record.raw.text,record.raw.url);
                                    }else{
                                        if(record.isExpanded()){
                                            this.collapseNode(record);
                                        }else{
                                            this.expandPath(record.getPath());
                                        }
                                    }
                                }
                            }
                        }
                    });
    var panelCenter=Ext.create('Ext.tab.Panel',{
                        region:'center',
                        items: [{
                            title: '首页',
                            html:''
                            /*listeners:{
                            	resize:{
                            		fn:function(p, width, height, oldWidth, oldHeight, eOpts){
                            				p.body.update(p.body.getHTML());
                            		}
                            	}
                            },
                            html: '<iframe scrolling="auto" frameborder="0"  src="web/sy/sy.jsp" style="margin:0;padding:0;width:100%;height:100%;position:relative;" onload="showMsg(false)"></iframe>'*/
                        }]
                    });
    var panelSouth=Ext.create('Ext.panel.Panel',{
                        region:'south',
                        height:25,
                        html:southHtml()
                    });
    
    Ext.onReady(function(){
        Ext.create('Ext.container.Viewport',{
				            layout:'border',
				            items:[panelNorth,panelWest,panelCenter,panelSouth]
        });
        Ext.get('divLoading').hide();
        getSvrTime();
        Ext.get('swry_mc').dom.innerHTML='操作员：'+swry_mc;
        Ext.get('swjg_mc').dom.innerHTML='税务机关：'+swjg_mc;
    });
    /**
     * 添加tab标签
     * @param {} sTitle
     * @param {} sUrl
     */
    function addTab(sTitle,sUrl){
        if(!getTabForTitle(sTitle)){
            showMsg(true);
            panelCenter.add({
                title:sTitle,
                html: '<iframe scrolling="auto" frameborder="0"  src="'+sUrl+'" style="margin:0;padding:0;width:100%;height:100%;" onload="showMsg(false)"></iframe>',
                closable:true
            }).show();
        }
    }
    /**
     * 显示隐藏加载提示
     * @param {} flag
     */
    function showMsg(flag){
        if (flag) {
            Ext.get('sTabLoading').show();
        }else {
            Ext.get('sTabLoading').hide();
        }
    }
    /**
     * 查找特定标题的tab的标签
     * @param {} t
     * @return {Boolean}
     */
    function getTabForTitle(t){
        var tabs=panelCenter.items;
        for(var i=0;i<tabs.length;i++){
            if(tabs.items[i].title==t){
                panelCenter.setActiveTab(i);
                return true;
            }
        }
        return false;
    }
    /**
     * 获取服务器时间，刷新session
     */
    function getSvrTime(){
        var ajaxConfig={
            url:'GetServerTime',
            //params : {userName : 'tom',password : '123'},//请求参数   
            //customer : '自定义属性',//附加属性   
            callback:function(options,success,response){
            	/*
                var msg = ["请求是否成功：" ,success,"\n",   
                           "服务器返回值：",response.responseText];   
                alert(msg.join(''));
                */
                if (success){
                    Ext.get('svrtime').dom.innerHTML=response.responseText;
                }
            }
        };
        Ext.Ajax.request(ajaxConfig);
        setTimeout(getSvrTime,50000);
    }
    /**
     * 重新登录
     */
    function reLogin(){
        Ext.Msg.show({
            title:'注销',
            msg:'是否要注销？',
            width:300,
            buttons:Ext.Msg.OKCANCEL,
            icon: Ext.MessageBox.INFO,
            fn:function(buttonId,text,opt){
                if(buttonId=='ok'){
                	Ext.Ajax.request({
                 	   url:'logoutAction.action',
                 	   success: function(response){
                 	        //var text = response.responseText;
                 	        window.location.href = 'login.jsp';
                 	    }
                 	});
                    
                }
            }
        });
    }
    function exitSYS(){
        Ext.Msg.show({
            title:'退出系统',
            msg:'是否要退出系统？',
            width:300,
            buttons:Ext.Msg.OKCANCEL,
            icon: Ext.MessageBox.INFO,
            fn:function(buttonId,text,opt){
                if(buttonId=='ok'){
                	Ext.Ajax.request({
                	   url:'logoutAction.action',
                	   success:function(response){
                		   window.opener=null;window.open('about:blank','_self');window.close();
                	   }
                	});
                }
            }
        });
    }
    function about(){
        Ext.Msg.show({
            title:'关于',
            msg:'软件版本：1.0</br>服务单位：邢台金税科技有限责任公司 </br>服务热线：2219202 2219203',
            width:350,
            buttons:Ext.Msg.OK,
            icon: Ext.MessageBox.INFO
        });
    }
     function resetpwd(){
        if(!resetpwdDlg){
            var simple = Ext.create('Ext.form.Panel', {
                //frame:true,
                bodyStyle:'padding:5px 5px 0',
                fieldDefaults: {
                    msgTarget: 'side',
                    labelWidth: 90
                },
                defaultType: 'textfield',
                defaults: {
                    anchor: '100%'
                },  
                items: [
                        {fieldLabel: '旧密码',name: 'oldpwd',inputType:'password',maxLength:8,afterLabelTextTpl:'<span style="color:red;font-weight:bold" data-qtip="Required">*</span>',allowBlank: false},
                        {fieldLabel: '新密码',name: 'newpwd',inputType:'password',maxLength:8,afterLabelTextTpl: '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>',allowBlank: false},
                        {fieldLabel: '确认新密码',name: 'newpwd2',inputType:'password',maxLength:8,afterLabelTextTpl: '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>',allowBlank: false}
                ],
                buttons:[{text: '确定',
                          handler:function(){
                                        if(simple.getForm().isValid()){//验证通过
                                            if(simple.getValues().newpwd==simple.getValues().newpwd2){//两次输入的新密码一致
                                                simple.getForm().submit({
                                                    url:'changeUserPwdAction.action',
                                                    clientValidation:false,
                                                    waitMsg:'正在提交数据,请稍候...',
                                                    success: function(form, action){
                                                        Ext.Msg.alert('提示信息',action.result.msg); 
                                                        simple.getForm().reset();
                                                        resetpwdDlg.close();
                                                    },
                                                    failure: function(form, action) {
                                                        Ext.Msg.alert('提示信息',action.result.msg); 
                                                    }
                                                });
                                            }else{
                                                Ext.Msg.show({
                                                                    title:'提示信息',
                                                                    msg:'两次输入的新密码不一致，请检查！',
                                                                    width:300,
                                                                    buttons:Ext.Msg.OK,
                                                                    icon: Ext.MessageBox.INFO
                                                                 });
                                            }
                                        }else{
                                            Ext.Msg.show({
                                                                    title:'提示信息',
                                                                    msg:'输入的密码位数有误，请检查！',
                                                                    width:300,
                                                                    buttons:Ext.Msg.OK,
                                                                    icon: Ext.MessageBox.INFO
                                                                 });
                                        }
                                 }
                         },
                         {text: '重置',handler:function(){simple.getForm().reset();}},
                         {text:'关闭',handler:function(){resetpwdDlg.close();}}
                ]
            });
            resetpwdDlg = Ext.widget('window', {
                title: '修改密码',
                closeAction: 'hide',
                width: 400,
                height: 350,
                minHeight: 350,
                layout: 'fit',
                resizable: false,
                modal: true,
                items: simple
            });
        }
        resetpwdDlg.show();
    }
  